<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2018/12/27
  Time: 10:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<html>
<head>
    <title>Title</title>
    <meta charset="UTF-8"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/statics/js/jquery-1.11.0.js"></script>
    <script type="text/javascript">

        $(function () {
            $("#cbAll").click(function (){
                $("input[name='cbItem']").prop("checked",$("#cbAll").prop("checked"));
            });
        });

        function deleteAllNewsType() {
            var ids="-1";
            $("input[name='cbItem']").each(function (){

                if (!confirm("数据一旦删除无法恢复，请问您确定要删除吗？")){
                    return;
                }
                if (this.checked){
                    var id=$(this).val();
                    ids+=","+id;
                }
//                alert("1");
            });
            $.get("${pageContext.request.contextPath}/newstype/dodeleteall",{ids:ids},function (result){
                if (result=="1"){
                    alert("批量删除成功！")
                }else {
                    alert("批量删除失败！")
                }
                window.location=window.location;
            } );
        }

        function deleteNewsType(id) {

            if (!confirm("删除父类别会删除所有其子类别，确认删除吗？")){
                return;
            }

            $.get("/newstype/dodelete",{id:id},function (result) {
                if (result=="1"){
                    alert("删除成功");
                }else {
                    alert("删除失败");
                }
                window.location=window.location;
            });
        }
    </script>
    
</head>
<body>
<form action="${pageContext.request.contextPath}/newstype/list" method="post">
    <table>
        <tr>
            <td>类别名称：<input type="text" name="typeName" value="${newsType.typeName}"/></td>
            <td>父类别：<select name="parentId">
                <option value="0">==不限==</option>
                <c:forEach var="item" items="${plist}">
                    <option  <c:if test="${item.id==newsType.parentId}">selected</c:if>  value="${item.id}">${item.typeName}</option>


                </c:forEach>
            </select></td>
            <td><input type="submit" value="搜索"/>&nbsp;
                <a href="javascript:void(0)" onclick="deleteAllNewsType();">批量删除</a> </td>
        </tr>
    </table>
</form>

<table>
    <tr>
        <td><input type="checkbox" id="cbAll"/>ID</td>
        <td>类别名称</td>
        <td>父类别</td>
        <td>创建日期</td>
        <td>操作</td>
    </tr>
    <c:forEach items="${list}" var="li">
        <tr>
            <td><input type="checkbox" name="cbItem" value="${li.id}"/>${li.id}</td>
            <td>${li.typeName}</td>
            <td>${li.parentName}</td>
            <td><fmt:formatDate value="${li.createDate}" pattern="yyyy-MM-dd"/></td>
            <td><a href="${pageContext.request.contextPath}/newstype/update?id=${li.id}">修改</a> <a href="javascript:void(0)" onclick="deleteNewsType(${li.id});">删除</a></td>
        </tr>
    </c:forEach>

</table>

<p>共${pageTool.totalRecordCount}条数据，当前页第${pageTool.currPageNo}/${pageTool.pageCount}页，每页${pageTool.pageSize}条，
    <a href="${pageContext.request.contextPath}/newstype/list?typeName=${newsType.typeName}&parentId=${newsType.parentId}&currPageNo=1">首页</a>
    <a href="${pageContext.request.contextPath}/newstype/list?typeName=${newsType.typeName}&parentId=${newsType.parentId}&currPageNo=${pageTool.currPageNo-1}">前一页</a>
    <c:forEach var="prePage" items="${prePages}">
        <a href="${pageContext.request.contextPath}/newstype/list?typeName=${newsType.typeName}&parentId=${newsType.parentId}&currPageNo=${prePage}">${prePage}</a>
    </c:forEach>
    <b>${pageTool.currPageNo}</b>
    <c:forEach var="nextPage" items="${nextPages}">
        <a href="${pageContext.request.contextPath}/newstype/list?typeName=${newsType.typeName}&parentId=${newsType.parentId}&currPageNo=${nextPage}">${nextPage}</a>
    </c:forEach>
    <a href="${pageContext.request.contextPath}/newstype/list?typeName=${newsType.typeName}&parentId=${newsType.parentId}&currPageNo=${pageTool.currPageNo+1}">后一页</a>
    <a href="${pageContext.request.contextPath}/newstype/list?typeName=${newsType.typeName}&parentId=${newsType.parentId}&currPageNo=${pageTool.pageCount}">末页</a>

</p>

</body>
</html>